package jdbc;

import java.sql.*;

public class JDBCDemo8 {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎注册");
        try (Connection connection = DBUtil.getConnection()){

            Statement statement = connection.createStatement();
            String sql = "INSERT INTO userinfo (username,password,nickname,age) " +
                    "VALUES(?,?,?,?) ";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,userInfo.getUsername());
            ps.setString(2, userInfo.getPassword());
            ps.setString(3, userInfo.getNickname());
            ps.setInt(4,userInfo.getAge());
            ResultSet rs = ps.executeQuery();
            if(rs.next()){
                System.out.println("注册成功");
            }else{
                System.out.println("登录失败,用户名或密码不正确");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
